package com.neuedu.service.impl;

import com.neuedu.dao.UserDao;
import com.neuedu.dao.XiaoQuDao;
import com.neuedu.dao.impl.XiaoQuDaoImpl;
import com.neuedu.model.User;
import com.neuedu.model.XiaoQu;
import com.neuedu.service.XiaoQuService;
import com.neuedu.vo.PageVO;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


public class XiaoQuServiceImpl implements XiaoQuService {

    private XiaoQuDao xiaoQuDao=new XiaoQuDaoImpl();

    @Override
    public PageVO<XiaoQu> selectOnePage(Integer pageNo, Integer pageSize, String startTime, String endTime, String name) {
        Integer limitParams1=(pageNo-1)*pageSize;
        Integer limitParams2=pageSize;
        List<XiaoQu> xiaoQus = xiaoQuDao.selectPageList(limitParams1, limitParams2, startTime, endTime, name);
        int count = xiaoQuDao.selectCount(startTime, endTime, name);

        PageVO<XiaoQu> pageVO=new PageVO<>();
        pageVO.setCount(count);
        pageVO.setData(xiaoQus);
        pageVO.setPageNo(pageNo);
        pageVO.setPageSize(pageSize);
        pageVO.setPageCount(count/pageSize+(count%pageSize==0?0:1));
        return pageVO;
    }
    public static int number=1;
    @Override
    public int add(XiaoQu xiaoQu) {
        //XY20240319001
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMdd");
        Date date = new Date();
        String format = simpleDateFormat.format(date);
        String bianhao="XY"+format;
        if(number<10){
            bianhao=bianhao+"00"+number;
        }else if(number<100){
            bianhao=bianhao+"0"+number;
        }else{
            bianhao=bianhao+number;
        }
        xiaoQu.setBianhao(bianhao);
        SimpleDateFormat chuangjianshijianSdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String chuangjianshijian=chuangjianshijianSdf.format(date);
        xiaoQu.setChuangjianshijian(chuangjianshijian);

        return xiaoQuDao.add(xiaoQu);
    }

    @Override
    public int del(Integer[] ids) {

        return xiaoQuDao.del(ids);
    }

    @Override
    public XiaoQu findXiaoQuById(Integer id) {

        return xiaoQuDao.selectXiaoQuOne(id);
    }

    @Override
    public int editXiaoQuInfo(XiaoQu xiaoQu) {
        return xiaoQuDao.updateXiaoQu(xiaoQu);
    }

    @Override
    public List<XiaoQu> selectXiaoQuAll() {
        List<XiaoQu> xiaoQus = xiaoQuDao.selectAll();
//        for (int i = 0; i < xiaoQus.size(); i++) {
//            xiaoQus.get(i).getMingcheng();
//        }
        return xiaoQus;
    }
}
